import java.util.*;

/**
 * Created by qtbui on 2017/9/21.
 */
class Solution
{
    public String addBinary(String a, String b)
    {
        int length=Math.max(a.length(),b.length());
        a=AddZero(a,length);
        b=AddZero(b,length);

        String result="";
        int flag=0;

        for(int i=length-1;i>=0;--i)
        {
            int s=a.charAt(i)-0x30+b.charAt(i)-0x30+flag;
            if(s>=2)
            {
                s-=2;
                flag=1;
            }
            else
            {
                flag=0;
            }

            result=s+result;
        }

        if(flag==1)
        {
            result="1"+result;
        }

        return result;
    }

    private String AddZero(String t,int expectedLength)
    {
        if(t.length()>=expectedLength)
        {
            return t;
        }

        int needZero=expectedLength-t.length();
        while(needZero--!=0)
        {
            t="0"+t;
        }
        return t;
    }
}

public class test
{
    public static void main(String[] args)
    {
        System.out.println(new Solution().addBinary("11","1"));
    }
}
